from playhouse.migrate import *
from peewee import *

my_db = SqliteDatabase('my_database.db')
migrator = SqliteMigrator(my_db)

from peewee import *

database = SqliteDatabase('my_database.db')

class BaseModel(Model):
    class Meta:
        database = database

class Product(BaseModel):
    name = CharField()

    class Meta:
        table_name = 'product'

with my_db:
    my_db.create_tables([Product,])

Product.create(name = 'Big Peach')

price_field = IntegerField(default=0)
migrate(migrator.add_column('product', 'price', price_field))
db = migrator.database
columns = db.get_columns('product')
print(columns)


# coleifer 说的：
# It's unusual to do this online:

# 1.declare a model/schema
# 2.migrate it
# 3.use the new schema
# Because if you know you need a price field just put it on the model class from the start.

# If you really need to do this, then you can call this after you've run the migration:
# Product._meta.add_field('price', price_field)


